package com.huluobo.high3videoproject.mvp.live.presenter;

import com.huluobo.base.view.BasePresenter;
import com.huluobo.high3videoproject.bean.GiftBeanResult;
import com.huluobo.high3videoproject.mvp.live.model.LiveModel;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class LivePresenter extends BasePresenter<LiveContract.View> implements LiveContract.Presenter {
    private LiveModel liveModel = new LiveModel();

    @Override
    public void getGift() {
        liveModel.getGift().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<GiftBeanResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        compositeDisposable.add(d);
                    }

                    @Override
                    public void onNext(GiftBeanResult giftBeanResult) {
                        if (isAttach()) {
                            getView().onGetGiftSuccess(giftBeanResult);
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        if (isAttach()) {
                            getView().onGetGiftFailed(e.getMessage());
                        }
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
